

-- Namespace
	local _,mod = ...


-- Obj cache
	local regions = mod.regions


-- Region recycling
	local active = {}
	local recycle = {}
	
	for region in pairs(regions) do
		active[region] = {}
		recycle[region] = {}
	end
	
	local function finished(self)
		local region = self.__region
		
		local active = active[region]
		local recycle = recycle[region]
		
		local id = self.__id
		
		self:Update('reset')
		
		active[id] = nil
		self.__id = nil
		recycle[#recycle+1] = self
		self:Hide()
	end
	
	function mod:message(region,...)
		if not (...) then return end
		
		local active = active[region]
		local recycle = recycle[region]
		assert(active and recycle,'no region by that name! '..region)
		
		local obj = recycle[#recycle]
		if obj then
			recycle[#recycle] = nil
			obj:Show()
		else
			obj = regions[region]()
			obj.__region = region
			obj.Finished = finished
		end
		
		local id = #active+1
		active[id] = obj
		obj.__id = id
		obj:Update('order',id)
		obj:Update('message',...)
	end
